#include <iostream>

#include "net_tsdeque.hpp"

#define NUM_THREAD 32

int main()
{
    dw::net::tsdeque<uint32_t> tsdeq;

    // Allow the context to run its own thread
    // so that it won't block the main programe
    std::vector<std::thread> threads;
    threads.resize(NUM_THREAD);

    uint32_t cnt;
    for (cnt = 0; cnt < NUM_THREAD; ++cnt)
    {
        {
            std::thread thr = std::thread(
                [&](uint32_t id)
                {
                    std::cout << "ID: " << id << std::endl;
                    std::cout << tsdeq << std::endl;
                    tsdeq.push_front(id);
                    tsdeq.push_back(id);
                    std::cout << "ID: " << id << std::endl;
                    std::cout << tsdeq << std::endl;
                },
                cnt);
            threads.emplace_back(std::move(thr));
            std::cout << "Threads " << cnt << " created" << std::endl;
        }
    }

    std::cout << "Threads create finished" << std::endl;

    for (auto &thr : threads)
    {
        if (thr.joinable()) {
            try {
                thr.join();
                cnt--;
                std::cout << "Threads num to be joined: " << cnt << std::endl;
            } catch (std::exception& e) {
                std::cout << e.what() << std::endl;
            }
        }
    }

    return 0;
}